package com.document;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Rect;
import android.util.Log;
import android.view.View;
//实现截屏功能类 
public class ShotView {
	static void shot(Activity activity,String filepath) { 
	       //View是你需要截图的View 
			 View view = activity.getWindow().getDecorView(); 
			 view.setDrawingCacheEnabled(true); 
	         view.buildDrawingCache(); 
	         Bitmap b1 = view.getDrawingCache(); 
	       // 获取状态栏高度 /
			   Rect frame = new Rect();
			 activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
	         int statusBarHeight = frame.top;
	         Log.i("TAG", "" + statusBarHeight);
	         System.out.println("statusBarHeight"+statusBarHeight);
	         // 获取屏幕长和高
	         int width = activity.getWindowManager().getDefaultDisplay().getWidth();
	         int height = activity.getWindowManager().getDefaultDisplay().getHeight();
	        // 去掉标题栏
				Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455);
	         b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight);
			view.destroyDrawingCache();
			FileOutputStream fos;
			try {
				fos = new FileOutputStream(filepath);
				b.compress(CompressFormat.PNG, 100, fos);
			} catch (FileNotFoundException e) {
				
				e.printStackTrace();
			}
		
			System.out.println("success");
	    }
}
